from time import sleep

import pytest
from appium.webdriver.common.appiumby import AppiumBy
from loguru import logger

from basic.basedriver import DRIVER
from page.page_navigate_main import PageMain

MAIN = PageMain()

@pytest.fixture(scope="function",autouse=True)
# def back_to_main():
#     logger.debug(f"{'='*20}开始执行用例{'='*20}")
#     yield
#     DRIVER.terminate_app('com.xiaomi.shop')
#     sleep(5)
#     DRIVER.activate_app('com.xiaomi.shop')
def back_home():
    logger.debug(f"{'=' * 20}开始执行用例{'=' * 20}")
    yield
    while DRIVER.current_activity != "com.xiaomi.shop2.activity.MainActivity":
        DRIVER.back()
    DRIVER.find_element(AppiumBy.XPATH, "//*[@text=\"首页\"]").click()
    logger.debug(f"{'=' * 20}返回首页{'=' * 20}")